{% extends "base.html" %}

{% block content %}
<script type="text/javascript" src="/static/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/static/js/jquery.cookie.min.js"></script>
<script type="text/javascript" src="/static/js/artDialog/jquery.artDialog.js?skin=default"></script>
<script type="text/javascript" src="/static/js/artDialog/plugins/iframeTools.js"></script>
{{ttt}}
{% ifequal is_con 0 %}
<div class="form-div">
  <form action="" method="get" name="searchForm">
    <img src="/static/images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
	ListName:
		<input type='text' name='listname' value='{% if listname %}{{listname}}{%endif%}'/>
	AddUser:
		<input type='text' name='adduser' value='{% if adduser %}{{adduser}}{%endif%}'/>
	<input type="button" value="Search" id='search' class="g-button g-button-submit"/>
  </form>
</div>
<script>
$(function(){
	$("#search").bind({
		click:function(){
			var t = this
			if(t.style.cursor == 'wait'){
				return false;
			}
			t.style.cursor = 'wait'
			var data = $('form[name="searchForm"]').serializeArray()
			var datas = {'is_con':1}
			for(var i=0;i<data.length;i++){
				datas[data[i].name] = data[i].value
			}
			$.ajax({
				url:'',
				data:datas,
				type:'get',
				dataType:'html',
				success:function(e){
					t.style.cursor = 'pointer'
					$('#return').html(e)
				}
			})
		}
	})
});
</script>
{% endifequal %}
<div id="return">
	<table width="100%" align="center" cellpadding="1" class="aui-ibox-data aui-dotted-split">
	  <thead>
		<tr>
			<th align="left" width="50">Selected</th>
			<th align="left" width="80">LetterID</th>
			<th align="left" width="150">LetterName</th>
			<th align="left" width="">HtmlUrl</th>
			<th align="left" width="120">AddTime</th>
			<th align="left" width="80">AddUser</th>
			<th align="left" width="80">Operate</th>
		</tr>
	  </thead>
	  <tbody>
	  {% if letters %}
		{%for m in letters %}
		<tr>
			<td align="left"><input type='radio' letterid="{{m.3}}" gmid="{{m.0}}" lettername="{{m.2}}" letterpath="{{m.1}}" name='seluser' class="sel-val"></td>
			<td align="left">{{m.3}}</td>
			<td align="left">{{m.2}}</td>
			<td align="left"><a title="点击查看详情" href="{{m.1}}" class="mailpath">{{m.1}}</a></td>
			<td align="left">{{m.6}}</td>
			<td align="left">{{m.7}}</td>
			<td align="left">
			</td>
		</tr>
		{% endfor %}
	  {%else%}
	    <tr>
			<td align="center" valign="center" height="60" colspan="10" style="color:green;font-size:16px;line-height: 60px;">No Results !</td>
		</tr>
	  {%endif%}
		<tr>
			<td align="left"></td>
			<td colspan='5'>
				<input type="button" name="close_win" class="g-button g-button-submit" value="OK">
				&nbsp;Total:&nbsp;<span style="color:red;" id="selectnum">0</span>&nbsp;
			</td>
		</tr>
		<tr>
			<td align="center" colspan="10">
				<div id="pages" class="pager"></div>
			</td>
		</tr>
	  </tbody>
	</table>
	<style>
		.emaillist{
			float:left;
			padding:3px;
			margin:2px;
			border:1px solid #def;
		}
		.emaillist:hover{
			background:#efefef;
			cursor:pointer;
		}
	</style>
	<script>
		var parent = art.dialog.top
		$('input[name="close_win"]').click(function(){art.dialog.close();})
		$('tr').find('td').click(function(){
			if($(this).children('input[type="radio"]').length>0)return;
			$(this).parents('tr').find('input[type="radio"]').each(function(){
				var letterid = $(this).attr('letterid')
				var gmid = $(this).attr('gmid')
				var lettername = $(this).attr('lettername')
				var letterpath = $(this).attr('letterpath')
				if(this.checked){
					this.checked = false
					$('#selectnum').text(0)
					parent.$('input#newletterid').val('')
					parent.$('input#letid').val('')
					parent.$('#lettername').val('')
					parent.$('#edit_content').show()
					parent.$('#letter_con').hide()
					art.dialog.data('letterid','')
				}else{
					this.checked = true
					$('#selectnum').text(1)
					parent.$('input#newletterid').val(letterid)
					parent.$('input#letid').val(gmid)
					parent.$('#lettername').val(lettername)
					parent.$('#edit_content').hide()
					parent.$('#letter_con').show()
					parent.$('#letter_con').html('<iframe src="'+letterpath+'" width="1000" height="500"></iframe>')
					art.dialog.data('letterid',letterid)
				}
			})
		})
		$('input[type="radio"]').click(function(){
			var letterid = $(this).attr('letterid')
			var gmid = $(this).attr('gmid')
			var lettername = $(this).attr('lettername')
			if(this.checked){
				$('#selectnum').text(1)
				parent.$('input#newletterid').val(letterid)
				parent.$('input#letid').val(gmid)
				parent.$('#lettername').val(lettername)
				parent.$('#edit_content').hide()
				art.dialog.data('letterid',letterid)
			}else{
				$('#selectnum').text(0)
				parent.$('input#newletterid').val('')
				parent.$('input#letid').val('')
				parent.$('#lettername').val('')
				parent.$('#edit_content').show()
				art.dialog.data('letterid','')
			}
		})
		$('a.mailpath').click(function(){
			var url = $(this).attr('href')
			var dialog = art.dialog({'id':'N1006','title':'EmailInfo',ok:true})
			$.get(url,function(e){
				dialog.content(e)
			})
			return false;
		})

		function initdata(){
			var letterid = art.dialog.data('letterid')
			$('input[type="radio"]').each(function(){
				if(parseInt($(this).attr('letterid')) == parseInt(letterid)){
					this.checked = true
					$('#selectnum').text(1)
				}
			})
			var tolpage = {{tolpage}}
			if(tolpage<=1)return false;
			for(var i=1;i<=tolpage;i++){
				var c = ''
				if(i=={{page}}){
					c = 'active'
				}
				$('#pages').append("<li><a href='?is_con=1&listname={% if listname %}{{listname}}{%endif%}&adduser={% if adduser %}{{adduser}}{%endif%}&page="+i+"' onclick=\"$.get(this.href,function(e){$(\'#return\').html(e)});return false;\" class='"+c+"'>"+i+"</a></li>")
			}
		}
		initdata()
	</script>
</div>
{% endblock %}